﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MoveBtn : MonoBehaviour
{
    private Button btn_Up;
    private Button btn_Down;
    private Button btn_Left;
    private Button btn_Right;

    void Awake()
    {
        Init();
    }


    public void Init()
    {
        Debug.Log(transform.Find("btn_Up"));

        btn_Up = transform.Find("btn_Up").GetComponent<Button>();
        btn_Down = transform.Find("btn_Down").GetComponent<Button>();
        btn_Left = transform.Find("btn_Left").GetComponent<Button>();
        btn_Right = transform.Find("btn_Right").GetComponent<Button>();
        btn_Up.onClick.AddListener(() => {
            if(GameManager.Instance.IsGameStarted && !GameManager.Instance.IsGameOver)
                EventCenter.Broadcast(EventDefine.Move,Direction.Up);
        });
        btn_Down.onClick.AddListener(() => {
            if (GameManager.Instance.IsGameStarted && !GameManager.Instance.IsGameOver)
                EventCenter.Broadcast(EventDefine.Move, Direction.Down);
        });
        btn_Left.onClick.AddListener(() => {
            if (GameManager.Instance.IsGameStarted && !GameManager.Instance.IsGameOver)
                EventCenter.Broadcast(EventDefine.Move, Direction.Left);
        });
        btn_Right.onClick.AddListener(() => {
            if (GameManager.Instance.IsGameStarted && !GameManager.Instance.IsGameOver)
                EventCenter.Broadcast(EventDefine.Move, Direction.Right);
        });
    }

}
